{extend name="layout:base" /}{block name="content"}

<?php
$global=isSupperManagerForSession();
?>
<link rel="stylesheet" type="text/css" href="/static/My97DatePicker/skin/WdatePicker.css" />
<script charset="utf-8" src="/static/My97DatePicker/WdatePicker.js"></script>
<style type="text/css">
    .yg_inp>input{margin-bottom: 10px;}
    #zc_detail table{margin:10px;}
    #zc_detail table tr td{border: 1px solid #ddd;height:40px;line-height:40px;padding-left:5px;padding-right:5px;}
    .ordertable input {width:90%;}
    .policeLable{padding:2px 4px;margin-left:4px;}
    #taskDate .taskDateItem{width:100%;height:40px;line-height:40px;margin:4px 0px;}
    #taskDate .taskDateItem .taskDateItemLeft{width:10%;float:left;}
    #taskDate .taskDateItem .taskDateItemRight1{width:70%;float:left;border:1px solid #139667;height: 42px;}
    #taskDate .taskDateItem .taskDateItemRight2{width:20%;float:right;}
    #taskDate .taskDateItem .opUsers img{width:22px;margin-left:5px;}
    #taskDate .taskDateItem .itemUser{padding: 4px 6px;background:#139667;margin-left:4px;color:white;}
    #taskDate .taskDateItem .clear{clear:both;width:0px;height:0px;overflow:hidden;}
    #taskDate .taskDateItem .jia,#taskDate .taskDateItem .jian{font-size:30px;cursor:pointer;font-weight:800;margin-left:5px;}

    #attr .attrItem{width:80%;border:1px solid #ccc;margin-top:10px;font-size:12px;background-color:#efefef;}
    #attr .attrItem .attrItemName{width:98%;margin-top:10px;margin-left:auto;margin-right:auto;}
    #attr .line{width:98%;margin-left:auto;margin-right:auto;border-top:1px solid #ccc;height:1px;overflow:hidden;}
    #attr .attrItemValDiv{width:98%;margin-left:auto;margin-right:auto;}
</style>

<!--引入JS-->
<script type="text/javascript" src="/static/admin/js/ajaxfileupload.js?t=1"></script>
<script type="text/javascript" charset="utf-8" src="/static/ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="/static/ueditor/ueditor.all.min.js"> </script>
<script type="text/javascript" charset="utf-8" src="/static/ueditor/lang/zh-cn/zh-cn.js"></script>

<section class="topBanners">
         <div class="icon"></div>
         <div class="topBannersNav">
        <span data-url="/admin/hosparticle/lists" onclick="ContentLoadGo('/admin/hosparticle/lists')">文章管理</span>
         >
         <span data-url="/admin/hosparticle/addData"  onclick="ContentLoadGo('/admin/hosparticle/addData')"  >添加</span>
         </div>
</section>
<section id="zc_detail">
<table class="ordertable" style="width:100%;" border="0" cellspacing="0" cellpadding="0">
    <tr>
        <td width="120"><div align="right">类型</div></td>
        <td class="tr_cons">
            <select id="bigtype" class="ser_stats select" name="data[bigtype]">
                <?php
            foreach($bigTypeLists as $k=>$v){
                ?>
                <option value="<?php echo $v['id']; ?>" <?php if($info['bigtype']==$v['id']){echo 'selected';} ?> ><?php echo $v['name'] ?></option>
                <?php
                }
        ?>
            </select>
        </td>
    </tr>

    <tr>
        <td width="120"><div align="right">文章分类</div></td>
        <td class="tr_cons">
            <select id="pid" class="select" name="data[pid]">
                <option value="">--分类--</option>
                <?php
                foreach($allTypeLists as $key=>$val)
                {
                ?>
                <option value="<?php echo $val['id']; ?>" <?php if($info['pid']==$val['id']){echo 'selected';} ?> ><?php echo $val['name']; ?></option>
                <?php
                }
                ?>
            </select>
        </td>
    </tr>



     <tr>
       <td width="120"><div align="right">文章名称</div></td>
       <td class="tr_cons">
       <input type="text" name="data[name]" id="name" value="<?php echo $info['name']; ?>" placeholder="" class="textbox" style="padding:0px;" />
       </td>
     </tr>
    <tr>
        <td width="120"><div align="right">作者</div></td>
        <td class="tr_cons">
            <input type="text" name="data[author]" id="author" value="<?php echo $info['author']; ?>" placeholder="" class="textbox" style="padding:0px;" />
        </td>
    </tr>
     
     <tr>
       <td width="120"><div align="right">是否推荐</div></td>
       <td class="tr_cons">
       <select name="data[hot]" id="hot" class="select">
      		<option value="0">普通</option>
		    <option value="1">推荐</option>
      		</select></td>
     </tr>
     
      <tr>
       <td width="120"><div align="right">是否上架</div></td>
       <td class="tr_cons">
       <select name="data[stats]" id="stats" class="select">
      		<option value="0">上架</option>
		    <option value="1">下架</option>
      		</select></td>
     </tr>
     
      <tr>
         <td><div align="right">封面图</div></td>
         <td>
            <form id="jvForm" name="jvForm" action="/api/face/updateImage1" method="post" enctype="multipart/form-data">
                <input type="hidden" name="data[img]" id="uImage" value="<?php echo $info['img'] ?>" />
                <a style="position:relative;display:inline-block;width:100px;height:30px;background:#EEE;border:1px solid #999;text-align:center;line-height:30px;"  href="javascript:void(0);" >上传文件
                <input style="position:absolute;left:0;top:0;width:100px;height:30px;z-index:999;opacity:0;" onchange="uploadPic()" type="file" name="file" id="fileImage"  />
                </a>
                <input type="button" power="70000"  style="display:inline-block;width:100px;height:30px;background:#EEE;border:1px solid #999;text-align:center;line-height:30px;color:rgb(6, 193, 174);" value="裁剪上传" class="uImage"/>
                <div id="updateimg"></div>
            </form>
         </td>
      </tr>



    <tr>
         <td><div align="right">内容</div></td>
         <td colspan="7">
            <script id="editor" type="text/plain" style="width:96%;height:500px;"></script> 
         </td>
      </tr>
    <tr>
         <td width="120"><div align="right">排序</div></td>
         <td class="tr_cons">
             <input type="text" name="data[sorts]" id="sorts" value="<?php echo $info['sorts']; ?>" placeholder="" class="textbox" style="padding:0px;width:100px;" />越大越靠前
             </td>
   </tr>


     <tr>
       <td style="height:50px;text-align:center;" colspan="2">
			<input type="button" power="70000"  style="width:80px;margin-top:4px;margin-bottom:4px;padding:0px;" value="添加" class="link_btn add"/>
       </td>
     </tr>
   </table>
</section>
<script type="text/javascript">
    var ue = UE.getEditor('editor').addListener("ready", function () {});
</script>

<script type="text/javascript">
function uploadPic()
{
    $.ajaxFileUpload({
        url: '/api/face/uploadImage1', //用于文件上传的服务器端请求地址
        secureuri: false, //是否需要安全协议，一般设置为false
        fileElementId: 'fileImage', //文件上传域的ID
        dataType: 'text/plain', //返回值类型 一般设置为json
        success: function (data, status) //服务器成功响应处理函数
        {
         if(data.err==0)
           {
               var img='<a href="'+data.data.pic+'" target="_blank"><img src="'+data.data.pic+'" style="width:120px;margin:5px;" />';
               $("#updateimg").html(img);
               $("#uImage").val(data.data.pic);
           }
       },
       error: function (data, status, e)//服务器响应失败处理函数
       {
        alert(e);
       }
    })
   return false;
}

function myResearch(){
   var url="/admin/hosparticle/addData";
   var param={
   };
   ContentGet(url,param);
}

/**
 *
 * @returns 0表示检查通过 1检查不通过
 */
function checkGoodAttr()
{
    var flag=0;
    var attr=[];
    $("#attr .attrItem").each(function(k,v){
        var valItem ={name:"",val:[]};
        var name =$(v).find(".attrName:eq(0)").val();
        valItem.name=name;
        $(v).find(".attrVal").each(function(k1,v1){
            var tmpVal=$(v1).val();
            if(tmpVal!="")
            {
                valItem.val.push(tmpVal);
            }
        })
        if(valItem.val.length>0)
        {
            if(valItem.name.length<=0)
            {
                flag=1;
            }
        }
    });
    return flag;
}

function getGoodAttr()
{
    var attr=[];
    $("#attr .attrItem").each(function(k,v){
        var valItem ={name:"",val:[]};
        var name =$(v).find(".attrName:eq(0)").val();
        valItem.name=name;
        $(v).find(".attrVal").each(function(k1,v1){
            var tmpVal=$(v1).val();
            if(tmpVal!="")
            {
                valItem.val.push(tmpVal);
            }
        })
        attr.push(valItem);
    });
    return attr;
}

$(function(){
    var gnum=0;
    var lastObj;
    //设置搜索栏
    $(".research").click(function(){
       var page =$(this).attr("page");
       $("#cpage").val(page);
       myResearch();
    });
    //文章属性相关
    $(".attrNameAdd").click(function () {
        var item='<div class="attrItem">\n' +
            '                    <div class="attrItemName">\n' +
            '                    名称：<input type="text" name="attrName[]" class="textbox attrName" style="width:100px;" >\n' +
            '                        <i class="fa fa-minus-square fa-lg attrNameminus"></i>\n' +
            '                    </div>\n' +
            '                    <div class="line"></div>\n' +
            '                    <div class="attrItemValDiv">\n' +
            '                            <div class="attrItemVal">&nbsp;&nbsp;&nbsp;&nbsp;值：<input type="text" name="attrVal[]" class="textbox attrVal" style="width:100px;" >\n' +
            '                                <i class="fa fa-plus fa-lg attrValAdd"></i>\n' +
            '                            </div>\n' +
            '                    </div>\n' +
            '                </div>';
        $("#attr").append(item);
    });
    $("body").on('click','.attrValAdd',function(){
        var item='<div class="attrItemVal">&nbsp;&nbsp;&nbsp;&nbsp;值：<input type="text" name="attrVal[]" class="textbox attrVal" style="width:100px;" >\n' +
           '                                <i class="fa fa-minus fa-lg attrValmius"></i>\n' +
            '                            </div>';
        $(this).parent().parent().append(item);
    });

    $("body").on('click','.attrValmius',function(){

        $(this).parent().remove();
    });

    $("body").on('click','.attrNameminus',function(){

        $(this).parent().parent().remove();
    });
   //文章属性相关

    //图片裁剪上传开始
    $(".uImage").click(function(){
        var that =this;
        var url="/admin/fileclip/uploadclip";
        var id="<?php echo $id;?>";//ID如果是编辑可以传入ID 如果是添加为0
        var dataid="uImage";//窗口隐藏后回显的id为该值的input框
        var msgshow="updateimg";//窗口隐藏后回显的id为该值的input框
        var width=710;//裁剪图片大小为该值
        var height=380;//裁剪图片大小为改值
        var param={
            id:id,
            msgshow:msgshow,
            width:width,
            height,height,
            dataid:dataid
        };
        MyContentLoad(url,param);
    });

    //图片裁剪上传结束

    $(".colorAdd").click(function(){
        var item ='<div class="item">\n' +
            '                    <input type="text" name="color[]" class="textbox colorItem" style="width:100px;">\n' +
            '                </div>';
        $("#shopcolor").append(item);
    });

    $(".sizeAdd").click(function(){
        var item ='<div class="item">\n' +
            '                    <input type="text" name="size[]" class="textbox sizeItem" style="width:100px;">\n' +
            '                </div>';
        $("#shopsize").append(item);
    });

    //相关选择开始
    var relationUrl="/admin/relationselect/select";
    var dataString="<?php echo $ids;?>";//已选择中的
    var msgshow="relationMsg";//窗口隐藏后回显的id为该值的input框
    $(".relationSelect").unbind().click(function(){
        var dataStringArr=[];
        $("#relationMsg .relationResultCSS").each(function(i,v){
            var id = parseInt($(v).attr("data-id"));
            var name = $(v).attr("data-name");
            dataStringArr.push({selectID:id,selectName:name});
        });
        var param={
            msgshow:msgshow,
            dataString:JSON.stringify(dataStringArr)
        };
        showRelationSelect(param);
    });

    $("body").on('click','.relationResultClose',function(){
        $(this).parent().remove();
    });
    function showRelationSelect(param)
    {
        MyContentLoad(relationUrl,param);
    }
    function getRelationData()
    {
        var selectIDS=[];
        $("#relationMsg .relationResultCSS").each(function(i,v){
            var id = $(v).attr("data-id");
            selectIDS.push(id);
        })
        return selectIDS;
    }
    //相关选择结束

    $(".add").unbind().bind("click",function(){

        var that =this;
        var url="/admin/hosparticle/addData";
        var generaData=$("[name^='data']");
        var name=$("#name").val();

        var content=UE.getEditor('editor').getContent();
        if(name=="") {
            ErrTiShi("文章名称不能够为空");return false;
        }
        //获取选择的关联数据开始
        var relationInputArr =getRelationData();
        var relationInput="";
        if(relationInputArr.length>0)
        {
            relationInput = relationInputArr.join(",");
        }
        //获取选择的关联数据结束
        var param={
                data:{},
                conts:content,
                relationInput:relationInput,
                sys_opt:'addData'//后台判断编辑操作
        };
        getFormData(generaData,param.data);

        AjaxRequest(url,param,function(data){
            if(data.err==0) {
                SuccessTiShi("操作成功");
                ContentLoadGo("/admin/hosparticle/lists");
            } else
            {
                ErrTiShi(data.msg);
            }
        });
    });

    //导航
    $(".topBannerItem").click(function(){
       var attArr = $(this).attr();
       goToSelfLink(attArr);
    });
});
</script>
{/block}